package com.sky.demo.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.sky.demo.R;

/**
 * @author LiBin
 * @ClassName: DialogManager
 * @Description: dialog管理类
 * @date 2015年3月26日 下午5:51:37
 */
public class DialogManager {
    /**
     * 得到自定义的progressDialog
     *
     * @param context
     * @return
     */
    public static Dialog createDialog(Context context) {

        View view = LayoutInflater.from(context).inflate(R.layout.loading_dialog, null);// 得到加载view
        ImageView spaceshipImage = (ImageView) view.findViewById(R.id.img);
        spaceshipImage.setBackgroundResource(R.drawable.anim_loading);
        AnimationDrawable drawable = (AnimationDrawable) spaceshipImage.getBackground();
        drawable.start();
        Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);// 创建自定义样式dialog

        loadingDialog.setCancelable(false);// 不可以用“返回键”取消
        loadingDialog.setContentView(view, new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));// 设置布局
        return loadingDialog;
    }

    /**
     * 得到自定义的progressDialog
     *
     * @param context
     * @return
     */
    public static Dialog createDialog01(Context context) {

        View view = LayoutInflater.from(context).inflate(R.layout.loading_dialog, null);// 得到加载view
        // 加载布局
        ImageView spaceshipImage = (ImageView) view.findViewById(R.id.img);
        spaceshipImage.setBackgroundResource(R.mipmap.loading);
        // 加载动画
        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
                context, R.anim.load_animation);
        // 使用ImageView显示动画
        spaceshipImage.startAnimation(hyperspaceJumpAnimation);
        // 创建自定义样式dialog
        Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);

        loadingDialog.setCancelable(false);// 不可以用“返回键”取消
        loadingDialog.setContentView(view, new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));// 设置布局

        return loadingDialog;

    }
}
